package com.tsystems.skilltest;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="transaction")
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
public class Transaction
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long   id;

    @XmlElement(name="name")
    private String clientName;

    @XmlElement(name="account")
    private int    accountNumber;

    @XmlElement(name="value")
    private int    value;

    public Transaction(String clientName,
                       int accountNumber,
                       int value)
    {
        this.id = -1;
        this.clientName = clientName;
        this.accountNumber = accountNumber;
        this.value = value;
    }

    public Transaction()
    {
        this.id = -1;
    }

    public long getId()
    {
        return id;
    }

    public String getClientName()
    {
        return clientName;
    }

    public int getAccountNumber()
    {
        return accountNumber;
    }

    public int getValue()
    {
        return value;
    }

    @Override
    public String toString() {
        return "Transaction{" +
                "id=" + id +
                ", clientName='" + clientName + '\'' +
                ", accountNumber=" + accountNumber +
                ", value=" + value +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Transaction that = (Transaction) o;

        if (accountNumber != that.accountNumber) return false;
        if (id != that.id) return false;
        if (value != that.value) return false;
        if (clientName != null ? !clientName.equals(that.clientName) : that.clientName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = (int) (id ^ (id >>> 32));
        result = 31 * result + (clientName != null ? clientName.hashCode() : 0);
        result = 31 * result + accountNumber;
        result = 31 * result + value;
        return result;
    }
}
